<?php
if (count($argv) < 3) {
    exit('useage: php tool.php source save');
}
if (!file_exists($argv[1])) {
    exit('source file not exists');
}
$source = file_get_contents($argv[1]);
if($source){
    $source = explode("\n",$source);
    $content = 'DAUMPLAYLIST';
    $rowIndex = 1;
    foreach ($source as $row){
        echo "process {$row} ... \r\n";
        $row = explode(',',$row);
        if(count($row) == 2){
            if($rowIndex == 1){
                $content .= "\nplayname={$row[1]}\ntopindex=110\nsaveplaypos=0\n";
            }
            $content .= "{$rowIndex}*file*$row[1]\n{$rowIndex}*title*$row[0]\n{$rowIndex}*played*0\n";
            $rowIndex ++;
        }
    }
    file_put_contents($argv[2],$content);
}
echo "process done!";